package com.show.mytest;

public class NightThread implements Runnable {
    private Employee e;
    private int index = 0;

    public NightThread(Employee e) {
        this.e = e;
    }

    @Override
    public void run() {
        while (true){
            synchronized (e){
                if (e == null){
                    try {
                        e.notify();
                        e.wait();
                    } catch (InterruptedException e1) {
                        e1.printStackTrace();
                    }
                }
                if (index % 2 == 0){
                    System.out.println(e + " 上夜班");
                } else {
                    System.out.println(e + " 上白班");
                }
                try {
                    e.notify();
                    e.wait();
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
            index++;
        }
    }
}
